<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Introduction</title>
<link rel="stylesheet" href="udtdoc.css" type="text/css" />
</head>

<body>
<div class="ref_head">&nbsp;UDT Tutorial</div>

<h3><font color="#000080">Configure UDT Options</font></h3>
<p>Options of UDT are read and set through <a href="opt.htm"><strong>getsockopt</strong></a> and <a href="opt.htm"><strong>setsockopt</strong></a> methods. Before modifying any option, bear in mind that it is NOT required that you modify the default options. If the application has sound performance with the default options, just use the default configurations.</p>

<p><strong>UDT_MSS</strong> is used to configure the packet size. In most situations, the optimal UDT packet size is the network MTU size. The default value is 1500 bytes. A UDT connection will choose the 
smaller value of the MSS between the two peer sides. For example, if you want to set 9000-byte MSS, you have to set this option at both sides, and one of the value has to be exactly equal to 
9000, and the other must not be less than 9000.</p>

<p>UDT uses a different semantics of synchronization mode from traditional sockets. It can set the sending and receiving synchronization independently, which allows more flexibility. 
However, UDT does not allow non-blocking operation on connection setup and close. The sychronization mode of sending and receiving can be set on <strong>UDT_SNDSYN</strong> and <strong>UDT_RCVSYN</strong>, respectively.</p>

<p>The UDT buffer size is (<strong>UDT_SNDBUF</strong> and <strong>UDT_RCVBUF</strong>) used to limit the size of temporary storage of sending/receiving data. The buffer size is only a limit and memory is allocated upon necessary. Generally, larger 
buffer (but not so large that the physical memory is used up) is better. For good performance the the buffer sizes for both sides should be at least <em>Bandwidth*RTT</em>.</p>

<p>UDT uses UDP as the data channel, so the UDP buffer size affects the performance. Again, a larger value is generally better, but the effects become smaller and disappear as the buffer 
size increases. Generally, the sending buffer size can be a small value, because it does not limit the packet sending much but a large value may increase the end-to-end delay.</p>

<p><strong>UDT_FC</strong> is actually an internal parameter and you should set it to not less than UDT_RCVBUF/UDT_MSS. The default value is relatively large, therefore unless you set a very large 
receiver buffer, you do not need to change this option.</p>

<p><strong>UDT_LINGER </strong>is similar to the SO_LINGER option on the regular sockets. It allows the UDT socket continue to sent out data in the sending buffer when close is called.</p>

<p><strong>UDT_RENDEZVOUS</strong> is used to enable rendezvous connection setup. When rendezvous mode is enabled, a UDT socket cannot call listen or accept; instead, in order to set up a rendezvous 
connection, both the peer sides must call connect at approximately the same time. This is useful in traversing a firewall.</p>

<p><strong>UDT_SNDTIMEO </strong>and <strong>UDT_RCVTIMEO </strong>are similar to SO_SNDTIMEO and SO_RCVTIMEO, respectively. They are used to set a timeout value for packet sending and receiving.</p>
<p><strong>UDT_REUSEADDR</strong> allows applications to decide whether to share a UDP port with other UDT connections. By default this option is true, which means all UDT connections that are <a href="bind.htm">bind</a> to 0 will try to reuse any existing UDP socket. In addition, multiple UDT connections can bind to the same port number other than 0. If UDT_REUSEADDR is set to false, an exclusive UDP port will be assign to this UDT socket. There are a few situations when UDT_REUSEADDR should be set to false. First, two UDT sockets cannot listen on the same port number, so either the second UDT socket is explicitly bound to a different port, or UDT_REUSEADDR is set to false for this UDT socket. Second, a UDT socket bound to a specific port number cannot connect to the other UDT socket bound to the same port on the same IP address. </p>
<p><strong>Example: read current UDT settings</strong></p>
<div class="code">
UDTSOCKET u;<br>
<br>
...<br>
<br>
bool block;<br>
int size = sizeof(bool);
<br>
UDT::getsockopt(u, UDT_SNDSYN, 0, &block, &size);
</div>

<p><strong>Example: modify UDT settings</strong></p>
<div class="code">
UDTSOCKET u;<br>
<br>
...<br>
<br>
bool block = false;<br>
<br>
UDT::setsockopt(u, UDT_SNDSYN, 0, &block, sizeof(bool));
</div>


<h5>See Also</h5>
<p><a href="opt.htm"><strong>getsockopt</strong></a>, <a href="recv.htm"><strong>setsockopt</strong></a> </p>
</body>
</html>
